import QtQuick
import QtQuick.Controls.Material


Item {

    width: inputWidth
    height: inputHeight

    property real inputWidth: 200
    property real inputHeight: 70


    // 背景属性:
    property real borderWidth: 1
    property string borderColor: "black"
    property string backColor: "white"

    // 内容属性
    property real fontPointSize: 30
    property bool fontBold: true
    property int maxDataLength: 10
    property string inputData
    property string showData
    property string fontColor: "black"

    property bool validatorFlag : true

    property var validator_Normal: RegularExpressionValidator{
        regularExpression: /^(-?\d+(\.\d{1,2})?\r*)?$/
    }

    property var validator_Word: RegularExpressionValidator{

    }

    // 信号
    signal  inputFinished()


    Rectangle{
        id: inputBackGround
        width: inputWidth
        height: inputHeight
        color: backColor
        radius: 10
        border.width: borderWidth
        border.color: borderColor

        Text{
            id: text
            anchors.centerIn: parent
            font.pointSize: fontPointSize
            font.bold: fontBold
            text: showData
            visible: !inputText.visible
            color: fontColor
            // echoMode : TextInput.Password
        }

        TextInput{
            id: inputText
            anchors.centerIn: parent
            font.pointSize: fontPointSize
            font.bold: fontBold
            visible: false
            color: fontColor
            maximumLength: maxDataLength
            // echoMode : TextInput.Password
            text: inputData

            validator: validatorFlag ?  validator_Normal : validator_Word


            onEditingFinished: {            
                inputText.visible = false
                inputData = inputText.text
                // showData = inputData
                inputFinished()
            }

        }

        MouseArea{
            anchors.fill: parent
            onClicked: {
                inputData = showData
                inputText.forceActiveFocus()
                inputText.visible = true
                inputText.selectAll()
                // console.log("触发点击 - 选中事件")

            }

            // onDoubleClicked: {
            //     // inputText.selectAll()
            //     // inputText.copy()
            // }
        }
    }

}
